package com.hxkcloud.patient.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.hxkcloud.patient.YjhApplication;

import java.util.List;

/**
 * Created by william_sun on 2016-07-05.
 * Description:SharedPreference操作
 */
public class SharedPreferenceUtil {


    private static final String DOCTORPATIENTLIST_HISTORY_KEYWORDS = "doctorpatientlist_history_keywords";//医生患者列表历史搜索记录

    private static final String NAME_KEY = "info";// SharedPreference's name
    private static final String STATUSBARHEIGHT_KEY = "statusbarheight";// 状态栏高度
    private static final String HISTORY_KEYWORDS = "history_ketwords";//文章搜索历史记录
    private static final String PATIENTLIST_HISTORY_KEYWORDS = "patientlist_history_keywords";//患者列表历史搜索记录
    private static final String YUNZHOU = "yun_zhou";//孕周
    private static final String STARTTIME = "starttime";//末次月经开始时间
    private static final String FENMIANTIME = "fenmian_time";//分娩时间
    private static final String ISRUNNING = "isrunning";//记录程序是否运行，home键返回再重启时根据这个判断是否程序登录
    private static final String LOGINACCOUNT = "loginaccount";//记录当前登录的手机账号
    private static final String LOGINPASSWORD = "loginpassword";//记录当前登录的手机password

    private static final String GUIDE = "guide";//引导页

    private static final String SYS_MSG = "sysmsg";//系统消息

    private static SharedPreferences Sp;
    private static SharedPreferences.Editor editor;

    private static void init(Context context) {
        if (Sp == null) {
            Sp = context.getSharedPreferences(NAME_KEY, Context.MODE_PRIVATE);
            editor = Sp.edit();
            editor.commit();
        }
    }

    public static int getStatusBarHeight(Context context) {
        init(context);
        if (YjhApplication.StatusBarHeight > 0) {
            return YjhApplication.StatusBarHeight;
        } else {
            YjhApplication.StatusBarHeight = Sp.getInt(STATUSBARHEIGHT_KEY, 0);
            return Sp.getInt(STATUSBARHEIGHT_KEY, 0);
        }
    }

    public static void saveStatusBarHeight(Context context, int height) {
        init(context);
        editor.putInt(STATUSBARHEIGHT_KEY, height).commit();
    }


    public static String getSysMsg(Context context) {
        init(context);
        return Sp.getString(SYS_MSG, "");
    }

    public static void setSysMsg(Context context, String msg) {
        init(context);
        editor.putString(SYS_MSG, msg.toString()).commit();
    }


    public static String getGuide(Context context) {
        init(context);
        return Sp.getString(GUIDE, "");
    }

    public static void setGuide(Context context, String guide) {
        init(context);
        editor.putString(GUIDE, guide.toString()).commit();
    }



    public static String getHistoryKeywords(Context context) {
        init(context);
        return Sp.getString(HISTORY_KEYWORDS, "");
    }

    public static void setHistoryKeywords(Context context, List<String> keywords) {
        init(context);
        editor.putString(HISTORY_KEYWORDS, keywords.toString()).commit();
    }

    public static String getPatientHistoryKeywords(Context context) {
        init(context);
        return Sp.getString(PATIENTLIST_HISTORY_KEYWORDS, "");
    }

    public static void setPatientHistoryKeywords(Context context, List<String> keywords) {
        init(context);
        editor.putString(PATIENTLIST_HISTORY_KEYWORDS, keywords.toString()).commit();
    }

    public static String getDoctorPatientHistoryKeywords(Context context) {
        init(context);
        return Sp.getString(DOCTORPATIENTLIST_HISTORY_KEYWORDS, "");
    }

    public static void setDoctorPatientHistoryKeywords(Context context, List<String> keywords) {
        init(context);
        editor.putString(DOCTORPATIENTLIST_HISTORY_KEYWORDS, keywords.toString()).commit();
    }

    public static String getYunZhou(Context context) {
        init(context);
        return Sp.getString(YUNZHOU, "");
    }

    public static void setYunzhou(Context context, String yunzhou) {
        init(context);
        editor.putString(YUNZHOU, yunzhou).commit();
    }

    public static String getStarttime(Context context) {
        init(context);
        return Sp.getString(STARTTIME, "");
    }

    public static void setStarttime(Context context, String starttime) {
        init(context);
        editor.putString(STARTTIME, starttime).commit();
    }

    public static String getFenmiantime(Context context) {
        init(context);
        return Sp.getString(FENMIANTIME, "");
    }

    public static void setFenmiantime(Context context, String fenmiantime) {
        init(context);
        editor.putString(FENMIANTIME, fenmiantime).commit();
    }

    public static boolean getIsrunning(Context context) {
        init(context);
        return Sp.getBoolean(ISRUNNING, false);
    }

    public static void setIsrunning(Context context, boolean is) {
        init(context);
        editor.putBoolean(ISRUNNING, is).commit();
    }

    public static String getLoginAccount(Context context) {
        init(context);
        return Sp.getString(LOGINACCOUNT, "");
    }

    public static void setLoginAccount(Context context, String account) {
        init(context);
        editor.putString(LOGINACCOUNT, account).commit();
    }

    public static String getLoginPassword(Context context) {
        init(context);
        return Sp.getString(LOGINPASSWORD, "");
    }

    public static void setLoginPassword(Context context, String password) {
        init(context);
        editor.putString(LOGINPASSWORD, password).commit();
    }
}
